﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mofang.Utils.LogProvider
{
	public class ConnectionService
	{
		/// <summary>
		/// Build Connection string
		/// <para>MYSQL Db</para>
		/// </summary>
		/// <param name="open"></param>
		/// <param name="convertZeroDatetime"></param>
		/// <param name="allowZeroDatetime"></param>
		/// <returns></returns>
		public static MySql.Data.MySqlClient.MySqlConnection GetMySqlConnection(bool open = true, bool convertZeroDatetime = false, bool allowZeroDatetime = false)
		{
			// logdb connection string db
			string cs = System.Configuration.ConfigurationManager.ConnectionStrings["logdb"].ConnectionString;
						
			var csb = new MySql.Data.MySqlClient.MySqlConnectionStringBuilder(cs);

			csb.AllowZeroDateTime = allowZeroDatetime;

			csb.ConvertZeroDateTime = convertZeroDatetime;

			var conn = new MySql.Data.MySqlClient.MySqlConnection(csb.ConnectionString);

			if (open) conn.Open();

			return conn;
		}
	}
}
